package com.xl.base.entity;

import java.util.Date;
import java.util.UUID;

import com.xl.base.page.BasePage;
import com.xl.core.util.DateUtils;
import com.xl.core.util.SessionLocalUtils;

public class BaseEntity extends BasePage {

	/**  */
	private static final long serialVersionUID = -8688517304895132357L;

	// 主键
	private String id;
	// 关系归属
	private String relation;
	// 创建人
	private String createBy;
	// 创建日期
	private Date createDate;
	// 更新人
	private String updateBy;
	// 更新时间
	private Date updateDate;
	// 备注
	private String remarks;
	// 删除标志（0：正常，1：已删除）
	private Integer delFlag;

	/**
	 * 删除枚举
	 */
	public static enum DELETED {
		NO(0, "未删除"), YES(1, "已删除");
		public int key;
		public String value;

		private DELETED(int key, String value) {
			this.key = key;
			this.value = value;
		}

		public static DELETED get(int key) {
			DELETED[] values = DELETED.values();
			for (DELETED object : values) {
				if (object.key == key) {
					return object;
				}
			}
			return null;
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getRelation() {
		return relation;
	}

	public void setRelation(String relation) {
		this.relation = relation;
	}

	public String getCreateBy() {
		return createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public String getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(String updateBy) {
		this.updateBy = updateBy;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public Integer getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(Integer delFlag) {
		this.delFlag = delFlag;
	}

	public Integer getNomalDelFlag() {
		return DELETED.NO.key;
	}

	public Integer getDeletedFlag() {
		return DELETED.YES.key;
	}

	public void preInsert() {
		this.setId(UUID.randomUUID().toString());
		this.setCreateDate(DateUtils.getDate());
		this.setUpdateDate(DateUtils.getDate());
		Operator operator = SessionLocalUtils.getOperator();
		if (operator != null && operator.getMember() != null) {
			this.setCreateBy(operator.getMember().getId());
			this.setUpdateBy(operator.getMember().getId());
		}
		this.setDelFlag(DELETED.NO.key);
	}

	public void preUpdate() {
		this.setUpdateDate(DateUtils.getDate());
		Operator operator = SessionLocalUtils.getOperator();
		if (operator != null && operator.getMember() != null) {
			this.setUpdateBy(operator.getMember().getId());
		}
	}
}
